package com.bootdo.system.controller;

import com.bootdo.system.domain.ApptupianDO;
import com.bootdo.system.domain.DayYingli;
import com.bootdo.system.domain.FormVO;
import com.bootdo.system.domain.JiaoyijiluDO;
import com.bootdo.system.service.ApptupianService;
import com.bootdo.system.service.FrontlogService;
import com.bootdo.system.service.JiaoyijiluService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;

@Controller
public class RecordController extends BaseController {

    @Autowired
    private JiaoyijiluService jiaoyijiluService;
    @Autowired
    private FrontlogService frontlogService;
    @Autowired
    private ApptupianService apptupianService;

    @GetMapping("/jiaoyijilu/tiaojianPage")
    public String jiaoyijilu() {
        return "tiaojianPage";
    }

    @GetMapping("/ezhangdan")
    public String ezhangdan(FormVO formVO, HttpServletRequest request) {

        ApptupianDO zhangdanleft = apptupianService.get(4);
        request.setAttribute("zhangdanleft", zhangdanleft);
        ApptupianDO zhangdanright = apptupianService.get(5);
        request.setAttribute("zhangdanright", zhangdanright);

        Long userId = getUserId(request);
        //交易账单
        formVO.setUserid(userId);
        List<JiaoyijiluDO> jiaoyijiluDOS = jiaoyijiluService.UserList(formVO);
        request.setAttribute("jiaoyijiluDOS", jiaoyijiluDOS);

        //写入盈利
        BigDecimal today = jiaoyijiluService.getTodayYingli(userId);
        request.setAttribute("today", today);

        BigDecimal allyingli = jiaoyijiluService.getAllYingli(userId);
        request.setAttribute("allyingli", allyingli);
        request.setAttribute("showyingli", 1);

        return "ezhangdan";
    }

    @GetMapping("/ezhangdan/everydayYinli")
    public String everydayYinli(HttpServletRequest request) {

        Long userId = getUserId(request);
        List<DayYingli> dayYinglis = jiaoyijiluService.everydayYinli(userId);
        request.setAttribute("dayYinglis", dayYinglis);

        return "everydayYinli";
    }

    @GetMapping("/bizhongjilu")
    public String bizhongjilu(Integer bizhongid, HttpServletRequest request) {

        List<JiaoyijiluDO> jiaoyijiluDOS = jiaoyijiluService.UserListWithBizhongid(getUserId(request), bizhongid);
        request.setAttribute("jiaoyijiluDOS", jiaoyijiluDOS);


        return "ezhangdan";
    }
}
